﻿#region Copyright (C) Sector7 Software Studio. All rights reserved
/*******************************************************************************************
 * Creation
 *      Author:         Wolf Lai
 *      Date:           2013/4/7 星期日 20:33:12
 *      Version:        
 * Modification 
 *      Author: 
 *      Date: 
 *      Description: 
 *      Version:
 *******************************************************************************************/
#endregion
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Sector7.Framework.DataDictionary.CORS;
using Sector7.Framework.DataDictionary.Utility;
using Sector7.Framework.Enums;
using Sector7.Framework.Core;

namespace Sector7.Framework.DataDictionary.Agents
{
    /// <summary>
    /// 数据元值类型服务代理
    /// </summary>
    public class ValueTypeServiceAgent
    {
        /// <summary>
        /// 添加数据元值类型
        /// </summary>
        /// <param name="type">数据元值类型</param>
        /// <returns>数据元值类型编号</returns>
        public static int Add(S7_ValueType type)
        {
            object typeId = WcfClient.GetInstance().Invoke<object>(
                service => service.AddValueType(type));

            return Convert.ToInt32(typeId);
        }

        /// <summary>
        /// 修改数据元值类型
        /// </summary>
        /// <param name="delta">数据元值类型改变量</param>
        /// <returns>操作结果</returns>
        public static int Set(EntityDeltaBase delta)
        {
            return WcfClient.GetInstance().Invoke<int>(
                service => service.SetValueType(delta));
        }

        /// <summary>
        /// 获取所有数据元值类型
        /// </summary>
        /// <returns>数据元值类型列表</returns>
        public static List<S7_ValueType> GetAll()
        {
            List<S7_ValueType> types = null;

            try
            {
                types = WcfClient.GetInstance().Invoke<List<S7_ValueType>>(
                    service => service.GetAllValueTypes());
            }
            catch (Exception e)
            {
                Log.WriteLine(LogSeverityType.WRN, "DAD", e);
            }

            return types;
        }
    }
}